<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/includes/tags.jsp" %>
<!-- webroot://WEB-INF/includes/admin/customer/list.jsp -->

<script type="text/javascript">
    function deleteUser(login, row) {
        var win = new JdsmCloseWindowHeader('testId');
        Insertion.Top(document.body, win.getElement());

        win.setTitle("Delete user");

        Insertion.Top(win.getContainer().getElement(), '<div style="text-align:center;">Confirm delete</div><div style="text-align:center"><table width="100%"><tr><td><input type="button" id="delButton" value="Delete"/> </td><td><input type="button" id="cancelButton" value="Cancel"/> </td></tr></table></div>');

        win.setWidth("150px");
        win.setHeight("75px");
        win.showCenter();
        Event.observe($('cancelButton'), 'click', function() {
            Element.remove(win.getElement());
        });
        Event.observe($('delButton'), 'click', function() {
            var process = new Element('div', {width: '100%', height: '100%', align:'center'});
            Insertion.Top(process, '<img src="/img/i/wait.gif"/>');
            Element.update(win.getContainer().getElement(), process);
            Position.Center(process, document.body);

            var link = '/admin/deleteUser.action' ;
            var params = 'login=' + login;
            new Ajax.Request(
                    (link),
            {
                method: "get",
                parameters: params,
                requestHeaders: {Accept: 'application/json'},
                onSuccess:function(transport) {
                    var jsonData = transport.responseText.evalJSON();
                    if ('error' == jsonData.result) {
                        alert(jsonData.message);
                    }
                    if ('success' == jsonData.result) {
                        Element.remove(row.parentNode.parentNode);
                        Element.remove(win.getElement());
                    }
                }
            }
                    );
        }
                )
                ;
    }
</script>
<div class="center_text">

    <displaytag:table name="usersWithRole" htmlId="id" style="width:100%;" id="userRoleTable" cellpadding="0"
                      cellspacing="0">
        <displaytag:column property="id"/>
        <displaytag:column title="Login">
            <s:url action="editUser" namespace="/admin" var="editUser" />
            <a href="${editUser}?login=${userRoleTable.login}">${userRoleTable.login}</a>
        </displaytag:column>
        <displaytag:column property="roleName"/>
        <displaytag:column property="rolePermission"/>
        <displaytag:column title="delete">
            <div onclick="deleteUser('${userRoleTable.login}', this);">delete</div>
        </displaytag:column>
    </displaytag:table>


</div>


<!-- webroot://WEB-INF/includes/admin/customer/list.jsp -->